package cn.com.dcsgo.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * WebMvcConfig
 * 1.controller
 * 2.handlerMapping
 * 3.handlerAdapter
 * 4.静态资源处理器
 * 5.jsp 视图解析前后缀
 * 6.json 解析器
 * 7.拦截器
 *
 * @author Dcsgo
 * @since 2025/3/7 6:15
 */
@EnableWebMvc
@Configuration
@ComponentScan({"cn.com.dcsgo.controller"})
public class WebMvcConfig implements WebMvcConfigurer {
    /**
     * 配置视图解析器
     * 自动将 xxx 转化为 /WEB-INF/views/xxx.jsp
     *
     * @param registry registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    /**
     * 配置静态资源处理器
     *
     * @param configurer configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    /**
     * 配置拦截器
     *
     * @param registry registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyHandlerInterceptor());
    }
}
